home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 5.2 KB | 176 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWAccBuf.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWSUBUFF_H
- #include "FWSUBuff.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwodutil
- #endif
-
- //========================================================================================
- // class FW_CStorageUnitBuffer
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CStorageUnitBuffer::FW_CStorageUnitBuffer
- //
- // This constructor just initializes some fields--no memory is actually allocated
- // for the buffer until Initialize() is called.
- //----------------------------------------------------------------------------------------
-
- FW_CStorageUnitBuffer::FW_CStorageUnitBuffer(long capacity) :
- fBuffer(NULL),
- fCapacity(capacity),
- fPosition(0),
- fValidBytes(0),
- fType(kInvalid),
- fInitialPosition(0)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStorageUnitBuffer::FW_CStorageUnitBuffer
- //
- // The copy constructor creates a buffer of the same size as that being
- // copied. No data is copied into the new buffer.
- //----------------------------------------------------------------------------------------
-
- FW_CStorageUnitBuffer::FW_CStorageUnitBuffer(const FW_CStorageUnitBuffer& otherBuffer) :
- fBuffer(NULL),
- fCapacity(otherBuffer.fCapacity),
- fPosition(0),
- fValidBytes(0),
- fType(kInvalid),
- fInitialPosition(0)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStorageUnitBuffer::~FW_CStorageUnitBuffer
- //----------------------------------------------------------------------------------------
-
- FW_CStorageUnitBuffer::~FW_CStorageUnitBuffer()
- {
- if (fBuffer)
- delete [] fBuffer;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStorageUnitBuffer::FW_CStorageUnitBuffer
- //
- // The assignment operator only changes the size of the buffer to match that of
- // the buffer it is being assigned to. No data is copied.
- //----------------------------------------------------------------------------------------
-
- FW_CStorageUnitBuffer& FW_CStorageUnitBuffer::operator=(const FW_CStorageUnitBuffer& otherBuffer)
- {
- if (this != &otherBuffer)
- {
- if (fCapacity != otherBuffer.fCapacity)
- {
- delete [] fBuffer;
-
- fBuffer = NULL;
- fCapacity = otherBuffer.fCapacity;
- fType = kInvalid;
- }
- }
-
- return (*this);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStorageUnitBuffer::Initialize
- //----------------------------------------------------------------------------------------
-
- void FW_CStorageUnitBuffer::Initialize(EBufferKind kind, long validBytes, long filePosition)
- {
- fPosition = 0;
- fValidBytes = validBytes;
- fType = kind;
- fInitialPosition = filePosition;
-
- if (!fBuffer && fType != kInvalid)
- fBuffer = new char[fCapacity];
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStorageUnitBuffer::ReadPeek
- //----------------------------------------------------------------------------------------
-
- const void* FW_CStorageUnitBuffer::ReadPeek(long& availableReadBytes)
- {
- if (fType != kReadPeek)
- {
- availableReadBytes = 0;
- return NULL;
- }
-
- availableReadBytes = fValidBytes - fPosition;
- FW_ASSERT(availableReadBytes >= 0);
- return fBuffer + fPosition;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStorageUnitBuffer::ReadPeekAdvance
- //----------------------------------------------------------------------------------------
-
- void FW_CStorageUnitBuffer::ReadPeekAdvance(long bytesRead)
- {
- FW_ASSERT(fType == kReadPeek);
- FW_ASSERT(bytesRead >= 0);
- fPosition += bytesRead;
- FW_ASSERT(fPosition <= fValidBytes);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStorageUnitBuffer::WritePeek
- //----------------------------------------------------------------------------------------
-
- void* FW_CStorageUnitBuffer::WritePeek(long& availableWriteBytes)
- {
- if (fType != kWritePeek)
- {
- availableWriteBytes = 0;
- return NULL;
- }
-
- availableWriteBytes = fValidBytes - fPosition;
- FW_ASSERT(availableWriteBytes >= 0);
- return fBuffer + fPosition;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStorageUnitBuffer::WritePeekAdvance
- //----------------------------------------------------------------------------------------
-
- void FW_CStorageUnitBuffer::WritePeekAdvance(long bytesWritten)
- {
- FW_ASSERT(fType == kWritePeek);
- FW_ASSERT(bytesWritten >= 0);
- fPosition += bytesWritten;
- FW_ASSERT(fPosition <= fValidBytes);
- }
-